﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IgrMensageiros.Util
{
    public static class Utils
    {
        #region "CONSTANTES"

        public const string Const_RegistroSalvo = "Registro Salvo com Sucesso!";
        public const string Const_PreencherCampos = "Preencher Campos Obrigatórios!";
        public const string Const_Senha_Diferente = "Confirma Senha esta diferente do campo Senha!";
        public const string Const_RegistroJaCadastrado = "Registro Já Cadastrado!";

        #endregion

        /// <summary>
        /// Método responsável em validar os campos da tela UI.
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static Boolean CamposObrigatorios(Control pControl)
        {
            bool retorno = true;

            if (pControl.GetType() == typeof(TextBox))
            {
                if (((TextBox)pControl).Text == string.Empty)
                {
                    retorno = false;
                    ((TextBox)pControl).BackColor = Color.Red;
                    ((TextBox)pControl).ForeColor = Color.White;
                }
                else
                {
                    ((TextBox)pControl).BackColor = Color.Azure;
                }
            }
            else if (pControl.GetType() == typeof(ComboBox))
            {
                if (((ComboBox)pControl).SelectedIndex < 0)
                {
                    retorno = false;
                    ((ComboBox)pControl).BackColor = Color.Red;
                    ((ComboBox)pControl).ForeColor = Color.White;
                }
                else
                {
                    ((ComboBox)pControl).BackColor = Color.Azure;
                }
            }
            
            return retorno;
        }

        /// <summary>
        /// Método responsável em limpar campos da tela UI.
        /// </summary>
        /// <param name="pControles"></param>
        public static void LimparCampos(Control pControles)
        {
            foreach (Control ctr in pControles.Controls)
            {
                if (ctr is TextBox)
                    (ctr as TextBox).Text = "";

                if (ctr is MaskedTextBox)
                    (ctr as MaskedTextBox).Text = "";

                if (ctr is ComboBox)
                    (ctr as ComboBox).SelectedIndex = -1;

                if (ctr is ListBox)
                    (ctr as ListBox).SelectedIndex = -1;

                if (ctr is RadioButton)
                    (ctr as RadioButton).Checked = false;

                if (ctr is CheckBox)
                    (ctr as CheckBox).Checked = false;

                if (ctr is CheckedListBox)
                {
                    foreach (ListControl item in (ctr as CheckedListBox).Items)
                        item.SelectedIndex = -1;
                }
            }
        }
    }
}
